/*
 * LowPass.cpp
 *
 *  Created on: Dec 4, 2009
 */

#include "LowPass.h"
#include <cmath>

LowPass::LowPass() {
}

LowPass::~LowPass() {
}

void LowPass::applyFilterInVector(int width, int height, int **vectors, int **newVectors) {
	if (vectors != NULL && newVectors != NULL) {
		#pragma omp parallel for default(shared)
		for (int i = 0; i < height; i++) {
			#pragma omp parallel for default(shared)
			for (int j = 0; j < width; j++) {
				double calculatedValue = vectors[i][j];

				calculatedValue += getUpLeftValue(i, j, width, height, vectors);
				calculatedValue += getUpCenterValue(i, j, width, height, vectors);
				calculatedValue += getUpRightValue(i, j, width, height, vectors);
				calculatedValue += getCenterLeftValue(i, j, width, height, vectors);
				calculatedValue += getCenterRightValue(i, j, width, height, vectors);
				calculatedValue += getDownLeftValue(i, j, width, height, vectors);
				calculatedValue += getDownCenterValue(i, j, width, height, vectors);
				calculatedValue += getDownRightValue(i, j, width, height, vectors);

				calculatedValue /= 9;

				newVectors[i][j] = (int) round(calculatedValue);
			}
		}
	}
}
